package sun.springboot.quartz_scheduler_integrate.core;

import org.quartz.*;
import sun.springboot.quartz_scheduler_integrate.core.model.JobConf;
import sun.springboot.quartz_scheduler_integrate.core.model.TriggerConf;

/**
 * 构建 调度器、job
 */
public class BuilderTJ {


    /**
     * 构建调度器
     */
    public static Trigger buildCronTrigger(TriggerConf triggerConf) {
        return TriggerBuilder.newTrigger()
                .withIdentity(triggerConf.getName(), triggerConf.getGroup())
                .withSchedule(CronScheduleBuilder.cronSchedule(triggerConf.getCronExpression()))
                .build();
    }

    /**
     * 构建job
     */
    public static JobDetail buildJobDetail(JobConf jobConf) {
        return JobBuilder
                .newJob(jobConf.getJob().getClass())
                .withIdentity(jobConf.getName(), jobConf.getGroup()).usingJobData(new JobDataMap(jobConf.getMap()))
                .build();
    }


}
